<?php
require_once("../../../config.inc.php");
require_once("../../../app/_inc/include.php");
require_once("./_inc/layoutFunction.php");

$objUser = $_SESSION[USEROBJ];
$numElem = 0;
$layout = sxREQUEST('layout');
$layout_alias = sxREQUEST('layout_alias');
$sSQL = "SELECT v.*, fv.label AS vlabel, fv.layout AS vlay, fv.band AS vband, fv.row AS vrow, fv.seq AS vseq, " .
		" fc.label AS clabel, fc.layout AS clay, fc.band AS cband, fc.row AS crow, fc.seq AS cseq, " .
		" fa.label AS alabel, fa.layout AS alay, fa.band AS aband, fa.row AS arow, fa.seq AS aseq " .
		" FROM layout_variable v " .
		" LEFT JOIN layout_field fv ON fv.variable = v.variable " .
		"    AND v.layout_alias = 'W' AND fv.layout = v.layout " .
		" LEFT JOIN layout_field fc ON fc.check_variable = v.variable " .
		"    AND v.layout_alias = 'W' AND fc.layout = v.layout  " .
		" LEFT JOIN layout_field fa ON fa.values_array = v.variable " .
		"    AND v.layout_alias = 'X'  AND fa.layout = v.layout " .
		" WHERE v.layout='$layout' AND v.layout_alias = '$layout_alias'" .
		" ORDER BY v.variable";
$query = $objSDAO->query($sSQL, "lay");

$aOpz = array("kMenu"=>'pro.lay');
echo(headerHTML($aOpz));
echo(bodyHTML($aOpz));

echo getLOHeader($layout);

$aCmd = array("ins"=>array("pag"=>"layoutVarIns.php?layout=$layout&layout_alias=$layout_alias",
										"title"=>_t("add new variable"),
										"text"=>_t("new variable"),
										"perm"=>"newmod"),
					"back"=>array()
					);
$sHtmlCmd = commandsHTML($aCmd);	
echo $sHtmlCmd;
if ($layout_alias=='W') {
	$loaDes = 'simple memory variable';
} elseif ($layout_alias=='X') {
	$loaDes = '1 dimension array memory variable';
} else {
	$loaDes = '???';
}
echo("<table class='tabl01' width=\"100%\" cellpadding=\"3\" cellspacing=\"2\">\n");
echo("<tr>" .
		"<td class=\"titl01\"colspan=\"6\">Layout variable $layout_alias - $loaDes</td>" .
	"</tr>\n");
echo("<tr>" .
		"<td class=\"tabh01\" width=\"20%\">Variable</td>" .
		"<td class=\"tabh01\" width=\"20%\">Domain</td>" .
		"<td class=\"tabh01\" width=\"1%\">Length</td>" .
		"<td class=\"tabh01\" width=\"1%\">Decimals</td>" .
		"<td class=\"tabh01\" width=\"20%\">Used as</td>" .
		"<td class=\"tabh01\" width=\"38%\">Field</td>" .
	"</tr>\n");	
while($row = $objSDAO->fetch("lay")){
	echo("<tr>" .
			"<td class=\"text01\" valign='top'>" .
				"<a class=\"text01\" ".
				goToPag("layoutVarView.php?layout=".$row["layout"].
				"&layout_alias=".$row["layout_alias"]."&variable=".$row["variable"]."&xsn=".XSN).
				" title=\""._t("View variable")."'".$row["variable"]."'\">".
				$row["layout_alias"]."_".$row["variable"]."</a>" .
			"</td>\n" .
			"<td class=\"text01\" valign='top'>".$row["domain"]."</td>" .
			"<td class=\"text01\" valign='top'>".$row["length"]."</td>" .
			"<td class=\"text01\" valign='top'>".$row["decimals"]."</td>" .
			"<td class=\"text01\" valign='top'>".
				((!empty($row["vlabel"]))?'value':'').
				((!empty($row["clabel"]))?'abilitation':'').
				((!empty($row["alabel"]))?'select value':'').
			"</td>" .
			"<td class=\"text01\" valign='top'>");
	if (!empty($row["vlabel"])) {
		echo "<a class=\"text01\" ".
				goToPag("layoutBandFieldMod.php?set=".$row["layout"].
				"&lay=".$row["vlay"]."&band=".$row["vband"]."&row=".$row["vrow"]."&seq=".
				$row["vseq"]."&xsn=".XSN)." title=\""._t("View field")."\">".
				$row["vlabel"]."</a>&nbsp;";
	}
	if (!empty($row["clabel"])) {
		echo "<a class=\"text01\" ".
				goToPag("layoutBandFieldMod.php?set=".$row["layout"].
				"&lay=".$row["clay"]."&band=".$row["cband"]."&row=".$row["crow"]."&seq=".
				$row["cseq"]."&xsn=".XSN)." title=\""._t("View field")."\">".
				$row["clabel"]."</a>&nbsp;";
	}
	if (!empty($row["alabel"])) {
		echo "<a class=\"text01\" ".
				goToPag("layoutBandFieldMod.php?set=".$row["layout"].
				"&lay=".$row["alay"]."&band=".$row["aband"]."&row=".$row["arow"]."&seq=".
				$row["aseq"]."&xsn=".XSN)." title=\""._t("View field")."\">".
				$row["alabel"]."</a>&nbsp;";
	}
	echo ("&nbsp;</td>" .
		"</tr>\n");
}
echo("</table>\n");
echo $sHtmlCmd;
echo(footerHTML());
exit();

